import enum
import json

CLASS_FORMAT_VERSION_MIN = 45
CLASS_FORMAT_VERSION_MAX = 52

class ConstantPoolTags(enum.Enum):
    CONSTANT_Class = 7
    CONSTANT_Fieldref = 9
    CONSTANT_Methodref = 10
    CONSTANT_InterfaceMethodref = 11
    CONSTANT_String = 8
    CONSTANT_Integer = 3
    CONSTANT_Float = 4
    CONSTANT_Long = 5
    CONSTANT_Double = 6
    CONSTANT_NameAndType = 12
    CONSTANT_Utf8 = 1
    CONSTANT_MethodHandle = 15
    CONSTANT_MethodType = 16
    CONSTANT_InvokeDynamic = 18

    def __str__(self):
        return'%d:%s' % (self.value, self.name)

class ConstantPoolTagsEncoder(json.JSONEncoder):
    def default(self, o):
        if isinstance(o, ConstantPoolTags):
            return str(o)
        return super().default(o)

def get_value_to_enum_from_constant_pool_tags():
    return { x[1].value : x[1] for x in ConstantPoolTags.__members__.items()}

MAGIC_NUMBER = b'\xCA\xFE\xBA\xBE'